﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace AncientEmpires_025_132
{
    public class AvatarCharacter : VisibleGameEntity
    {
        private string _characterName;
        public string CharacterName
        {
            get { return _characterName; }
            set { _characterName = value; }
        }

        private string _price;
        public string Price
        {
            get { return _price; }
            set { _price = value; }
        }

        // Năng lượng
        private string _mana;
        public string Mana
        {
            get { return _mana; }
            set { _mana = value; }
        }

        // Máu
        private string _healthPoints;
        public string HealthPoints
        {
            get { return _healthPoints; }
            set { _healthPoints = value; }
        }

        //Cấp độ
        private string _level;
        public string Level
        {
            get { return _level; }
            set { _level = value; }
        }

        //Sức mạnh (tấn công).
        private string _damage;
        public string Damage
        {
            get { return _damage; }
            set { _damage = value; }
        }
        
        //Phòng thủ
        private string _defense;
        public string Defense
        {
            get { return _defense; }
            set { _defense = value; }
        }

        //Quảng đường tối đa có thể di chuyển được.
        private string _maxDistance;
        public string MaxDistance
        {
            get { return _maxDistance; }
            set { _maxDistance = value; }
        }

        private Texture2D _textureCurrent;
        public Texture2D TextureCurrent
        {
            get { return _textureCurrent; }
            set { 
                    _textureCurrent = value;
                    if (_textureCurrent != null)
                    {
                        SizeTexture = new Vector2(_textureCurrent.Width, _textureCurrent.Height);    
                    }
                    
                }
        }

        private Vector2 _positionAvatar;
        public Vector2 PositionAvatar
        {
            get { return _positionAvatar; }
            set { _positionAvatar = value; }
        }

        private Vector2 _sizeAvatar;
        public Vector2 SizeAvatar
        {
            get { return _sizeAvatar; }
            set { _sizeAvatar = value; }
        }

        private bool _isSelected;
        public bool IsSelected
        {
            get { return _isSelected; }
            set { _isSelected = value; }
        }

        private int _numberOfClick = 0;
        public int NumberOfClick
        {
            get { return _numberOfClick; }
            set { _numberOfClick = value; }
        }

        public delegate void EventHandleSelected(AvatarCharacter avatar);
        public event EventHandleSelected EventSelected;


        public AvatarCharacter()
        {
        }
        public override void Update(GameTime gametime)
        {
            UpdateMouseState();
        }
        public override void UpdateMouseState()
        {
            MouseState ms = Mouse.GetState();
            if (!IsHide)
            {
                if (ms.LeftButton == ButtonState.Pressed
                    && ms.X > PositionAvatar.X && ms.X < PositionAvatar.X + SizeAvatar.X
                    && ms.Y > PositionAvatar.Y && ms.Y < PositionAvatar.Y + SizeAvatar.Y
                    )
                {
                    this.IsSelected = true;
                    EventSelected(this);
                }
            }
        }
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (!IsHide)
            {
                if (TextureCurrent != null)
                {
                    Rectangle rect = new Rectangle();
                    if (SizeAvatar.X == 0 && SizeAvatar.Y == 0)
                    {
                        SizeAvatar = new Vector2(TextureCurrent.Width, TextureCurrent.Height);
                    }
                    rect = new Rectangle((int)PositionAvatar.X, (int)PositionAvatar.Y, (int)SizeAvatar.X, (int)SizeAvatar.Y);
                    spriteBatch.Draw(TextureCurrent, rect, Color.White);
                }
            }
        }
    }
}
